<template>
  <div>
    <el-input v-model="keyword" placeholder="请输入关键字搜索" @keyup.enter.native="search" style="width: 300px;"></el-input>
    <el-button type="primary" @click="search">搜索</el-button>
    <el-table :data="posts">
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="content" label="内容"></el-table-column>
      <el-table-column prop="status" label="状态"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === '待审核'" size="mini" icon="el-icon-check" @click="approve(scope.row)">通过</el-button>
          <el-button size="mini" icon="el-icon-edit" @click="showDialog(scope.row)">编辑</el-button>
          <el-button size="mini" icon="el-icon-delete" @click="deletePost(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" title="编辑帖子">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="内容" prop="content">
          <el-input v-model="form.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="savePost">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      keyword: '',
      posts: [],
      dialogVisible: false,
      form: {}
    }
  },
  created() {
    this.fetchPosts()
  },
  methods: {
    fetchPosts() {
      // 调用后端接口获取帖子列表
    },
    search() {
      // 根据关键字搜索帖子
    },
    approve(post) {
      // 审核通过指定帖子
    },
    showDialog(post) {
      this.form = { ...post }
      this.dialogVisible = true
    },
    savePost() {
      // 保存编辑后的帖子信息
    },
    deletePost(post) {
      // 删除指定帖子
    }
  }
}
</script>